//
//  TextureUtils.m
//  OpenGLES_03
//
//  Created by Keisuke Hata on 09/12/24.
//  Copyright 2009 Keisuke Hata. All rights reserved.
//

#import "TextureUtils.h"

static GLuint currentTexName = -1;
static GLuint currentTexMinFilter = -1;
static GLuint currentTexMagFilter = -1;
static GLuint currentTexWrapS = -1;
static GLuint currentTexWrapT = -1;

static GLuint currentBlendSrc = -1;
static GLuint currentBlendDst = -1;

@implementation TextureUtils

+ (void) bindTexture2D : (Texture2D *)tex {

	if (tex.name != currentTexName ) {
		
		glBindTexture(GL_TEXTURE_2D, tex.name);
		currentTexName = tex.name;
	}
}

+ (void) setTextureUVOffset : (CGPoint)offs {
	
	glMatrixMode(GL_TEXTURE);
	glLoadIdentity();
	glTranslatef( offs.x, offs.y, 0.0f );
	
	// TEXTUREモードからモデルマトリックスに戻す
	glMatrixMode(GL_MODELVIEW);
}

+ (void) setTextureMinFilter: (NSInteger)filter {
	
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter );
	currentTexMinFilter = filter;
}

+ (void) setTextureMagFilter: (NSInteger)filter {
	
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter );
	currentTexMagFilter = filter;
}

//{GL_CLAMP_TO_EDGE,GL_REPEAT};
+ (void) setTextureWrapS: (NSInteger)wrap {
	
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap );
	currentTexWrapS = wrap;
}

+ (void) setTextureWrapT: (NSInteger)wrap {
	
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap );
	currentTexWrapT = wrap;
}

+ (void) setTextureBlend : (NSInteger)blend_s blendDst:(NSInteger)blend_d {
	
	glBlendFunc( blend_s , blend_d );
	currentBlendSrc = blend_s;
	currentBlendDst = blend_d;	
}

@end